import Vue from 'vue'
import config from 'utils/config'
// import registerComponent from './utils/libs/registerComponent'

// 临时过度

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import locale from 'element-ui/lib/locale/lang/zh-CN' // lang i18n

// 需要用到vuex时，打开
import store from './store'
import importI18n from './plugins/i18n'
import permission from './directive/permission'
import perm from './directive/perm'
import point from './directive/point'

// 加入公共的全局methods方法
import mixin from './views/mixins'
import Viewer from 'v-viewer'
import 'viewerjs/dist/viewer.css'

import './themes/styles/index.less' // global css
import './themes/icons'

import router from './routes'
import App from './App.vue'
import serviceApi from './api'
import View from './components/view'
import VueAMap from 'vue-amap'

Vue.use(Viewer)
Viewer.setDefaults({
  zIndexInline: 2017,
  Options: {
    inline: true,
    button: true,
    navbar: true,
    title: true,
    toolbar: true,
    tooltip: true,
    movable: true,
    zoomable: true,
    rotatable: true,
    scalable: true,
    transition: true,
    fullscreen: true,
    keyboard: true,
    url: 'data-source'
  }
})

Vue.use(VueAMap)
Vue.use(View)

Vue.config.productionTip = false

// 全局注册自定义组件
// registerComponent(Vue)

Vue.mixin(mixin)

Vue.use(ElementUI, {
  locale
})

// 国际化支持
const i18n = importI18n(Vue)

// 全局注册角色权限，主要是控制菜单按钮
Vue.use(permission)
Vue.use(perm)
Vue.use(point)

setTimeout(() => {
  VueAMap.initAMapApiLoader({
    key: config.amapKey,
    plugin: [
      'AMap.Autocomplete', //输入提示插件
      'AMap.PlaceSearch', //POI搜索插件
      'AMap.Scale', //右下角缩略图插件 比例尺
      'AMap.OverView', //地图鹰眼插件
      'AMap.ToolBar', //地图工具条
      'AMap.MapType', //类别切换控件，实现默认图层与卫星图、实施交通图层之间切换的控制
      'AMap.PolyEditor', //编辑 折线多，边形
      'AMap.CircleEditor', //圆形编辑器插件
      'AMap.Geolocation', //定位控件，用来获取和展示用户主机所在的经纬度位置
      'Geocoder' // 获取点击信息
    ],
    v: '1.4.4',
    uiVersion: '1.0'
  })
}, 50)

const globalVue = new Vue({
  el: '#app',
  i18n,
  router,
  store,
  render: h => h(App),
  beforeCreate() {
    // 表格、表单元素尺寸
    Vue.prototype.size = 'medium'
    // 添加全局事件bus
    Vue.prototype.eventBus = this
    // 接口服务
    Vue.prototype.$api = serviceApi
    // 全局消息提醒
    Vue.prototype.$msgTip = (message, type = 'success', duration = 1500) => {
      return new Promise(reslove => {
        this.$message({
          message,
          type,
          duration
        })
        setTimeout(() => {
          reslove()
        }, duration)
      })
    }
    Vue.prototype.$staticFile =
      process.env.NODE_ENV === 'production' && process.env.VUE_APP_BASEURLPATH !== '/'
        ? `${process.env.VUE_APP_BASEURLPATH}${process.env.VUE_APP_STATICFILE}`
        : process.env.VUE_APP_STATICFILE
    Vue.prototype.$filePath = process.env.VUE_APP_imagePath || process.env.VUE_APP_SERVERURL
  }
})

window.globalVue = globalVue
